package com.meitianhui.convenitenbuy.module.store.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.store.model.StoreOneLotteryBean;
import com.meitianhui.convenitenbuy.util.GlideUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/22.
 */

public class StoreOneLotteryAdapter extends BaseQuickAdapter<StoreOneLotteryBean.ActivityListEntity, BaseViewHolder> {
    private Context mContext;
    private Map<String, String> mUrlMap;
    private List<StoreOneLotteryBean.ActivityListEntity> mData;

    public StoreOneLotteryAdapter(Context context, @Nullable List<StoreOneLotteryBean.ActivityListEntity> data, Map<String, String> urlMap) {
        super(R.layout.item_store_one_lottery, data);
        mData = data;
        mContext = context;
        mUrlMap = urlMap;
        addFooterView(View.inflate(mContext, R.layout.item_store_one_lottery_bottom, null));
    }

    @Override
    protected void convert(BaseViewHolder helper, StoreOneLotteryBean.ActivityListEntity item) {
        helper.setText(R.id.tv_store_one_lottery_item, item.getTitle());
        helper.setText(R.id.tv_store_one_lottery_item_odd, item.getAward_name());
        helper.setBackgroundColor(R.id.view_store_one_lottery_item_line, mContext.getResources().getColor(helper.getPosition() == mData.size() - 1 ? R.color.white : R.color.bgColor));
        String type = item.getActivity_type();
        if (TextUtils.equals(type, "YYY")) {
            helper.setImageResource(R.id.iv_store_one_lottery_item, R.mipmap.store_one_lottery_item_1);
            helper.setBackgroundRes(R.id.rl_store_one_lottery_item, R.mipmap.store_one_lottery_item_bg1);
        } else if (TextUtils.equals(type, "GGL")) {
            helper.setImageResource(R.id.iv_store_one_lottery_item, R.mipmap.store_one_lottery_item_2);
            helper.setBackgroundRes(R.id.rl_store_one_lottery_item, R.mipmap.store_one_lottery_item_bg2);
        } else if (TextUtils.equals(type, "DSK")) {
            helper.setImageResource(R.id.iv_store_one_lottery_item, R.mipmap.store_one_lottery_item_3);
            helper.setBackgroundRes(R.id.rl_store_one_lottery_item, R.mipmap.store_one_lottery_item_bg3);
        }

        ImageView view = helper.getView(R.id.cv_store_one_lottery_item);
        GlideUtils.setRectImage(mContext,mUrlMap.get(item.getAward_pic_path1()), R.mipmap.icon_default_picture, R.mipmap.icon_default_picture, view);
    }

    public void setNewData(List data, Map<String, String> map) {
        setNewData(data);
        this.mUrlMap = map;
    }

    public Map<String, String> getUrlImage(){
        return mUrlMap;
    }



}
